package com.laozhao.test;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.EventQueue;
import java.awt.event.MouseEvent;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.SwingWorker;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import com.sun.awt.AWTUtilities;

public class DemoFrame extends JFrame {

	// 定义控件
	JPanel panel1;

	Container c;

	JMenuBar MenuB;

	JMenu SystemMenu, BookMGRMenu, BorrowBookMenu, ReturnBookMenu,
			InfoBrowseMenu, UserMGRMenu, BookkaMenu;

	JMenuItem UserLoginMenuItem, UserAddMenuItem, UserModifyMenuItem,
			UserDeleteMenuItem, ExitMenuItem, BookAddMenuItem,
			BookModifyMenuItem, BookDeleteMenuItem, BorrowBookMenuItem,
			BorrowInfoMenuItem, ReturnBookMenuItem, ReturnInfoMenuItem,
			BookListMenuItem, BorrowBookListMenuItem, UserListMenuItem,
			BookkaMenuItem, BookenvirMenuItem;

	JLabel titleLabel, AuthorLabel, DateLabel;
	
//	protected JButton button;
	//

	private JSlider slider = new JSlider();
	CloseableTabbedPane tab = new CloseableTabbedPane();
//	TabPanel tabP ;
	
	public static void main(String args[]) {

		EventQueue.invokeLater(new Runnable() {

			public void run() {

				try {
//					SwingWorker sw = new SwingWorker();
					setDefaultLookAndFeelDecorated(true);

					DemoFrame frame = new DemoFrame();

					frame.setVisible(true);

				} catch (Exception e) {

					e.printStackTrace();

				}

			}

		});

	}

	public DemoFrame() {

		super("XXX管理系统");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		initComponents();
		slider.addChangeListener(new SliderChangeListener());
//		tab.addChangeListener(new SliderChangeListener());
		tab.addCloseableTabbedPaneListener(new closeableTabbedPaneListener());
	}

	private void initComponents() {

		setScream();
		JPanel fPanel = new JPanel();
		fPanel.setName("WELCOME");

		for (int i = 0 ; i < 5 ; i ++){
			JPanel panel = new JPanel();
			panel.setName("panel & "+i);
			panel.add(new JLabel("选项卡："+i*100));
			tab.addTab("table " + i , panel);
		}
//		tabP = new TabPanel("**",tab);
		this.getContentPane().add(tab);
//		JTabbedPane tab = new JTabbedPane();
//		TabbedContainer tabc = new TabbedContainer();
//		tab.getta
//		tabbedcontainer tab

	}

	private class closeableTabbedPaneListener implements CloseableTabbedPaneListener {

		public boolean closeTab(int tabIndexToClose) {
			System.out.println(" &&&&&&& the index is :" + tabIndexToClose);
			return true;
		}

		public void mouseClicked(MouseEvent e) {
			// TODO Auto-generated method stub
			
		}

		public void mouseEntered(MouseEvent e) {
			
			
		}

		public void mouseExited(MouseEvent e) {
			// TODO Auto-generated method stub
			
		}

		public void mousePressed(MouseEvent e) {
			// TODO Auto-generated method stub
			
		}

		public void mouseReleased(MouseEvent e) {
			// TODO Auto-generated method stub
			
		}

		public void mouseDragged(MouseEvent e) {
			// TODO Auto-generated method stub
			
		}

		public void mouseMoved(MouseEvent e) {
			// TODO Auto-generated method stub
			
		}
		
	}
	
	private class SliderChangeListener implements ChangeListener {

		public void stateChanged( ChangeEvent e) {
			if(e.getSource() == slider){
				float v = slider.getValue() / 100f;
				System.out.println(v);
				AWTUtilities.setWindowOpacity(DemoFrame.this, v);// 设置窗体的透明度v
			}else if (e.getSource() == tab){
				System.out.println("*****************main listener*********************");
				System.out.println("^^^ tab.SelectedIndex = " + tab.getSelectedIndex());
//				System.out.println("^^^ tab.SelectedComponent = " + tab.getSelectedComponent().getName());
				System.out.println("^^^ tab.TabCount() = " + tab.getTabCount());
				System.out.println("^^^ the num of "+tab.getSelectedIndex()+" tab.Visible = " + tab.isVisible());
//				if(tab.getCloseComponent()!= null){
//					System.out.println("^^^ the close.tab = " + tab.getCloseComponent().getName());
////					tab.getCloseComponent().disable();
//					Component a = tab.getCloseComponent();
//					a  = null;
//					
//				}else{
//
//					System.out.println("^^^ the close.tab  is null" );
//				}
////				tab.addDTab(tab.getFirstTitle(),tab.getFirstPanel());
			}
		}

	}
	public void setScream(){

//		MenuB = new JMenuBar();
//		SystemMenu = new JMenu("系统管理");
//		UserMGRMenu = new JMenu("用户管理");
//		UserLoginMenuItem = new JMenuItem("用户登录");
//		UserAddMenuItem = new JMenuItem("添加用户");
//		UserModifyMenuItem = new JMenuItem("修改用户");
//		UserDeleteMenuItem = new JMenuItem("删除用户");
//		ExitMenuItem = new JMenuItem("退出");
//		SystemMenu.add(UserLoginMenuItem);
//		UserMGRMenu.add(UserAddMenuItem);
//		UserMGRMenu.add(UserModifyMenuItem);
//		UserMGRMenu.add(UserDeleteMenuItem);
//		SystemMenu.add(UserMGRMenu);
//		SystemMenu.add(ExitMenuItem);
//		MenuB.add(SystemMenu);
//		// /书籍管理菜单
//		BookMGRMenu = new JMenu("书籍管理");
//		BookAddMenuItem = new JMenuItem("添加书籍");
//		BookModifyMenuItem = new JMenuItem("修改书籍");
//		BookDeleteMenuItem = new JMenuItem("删除书籍");
//		BookMGRMenu.add(BookAddMenuItem);
//		BookMGRMenu.add(BookModifyMenuItem);
//		BookMGRMenu.add(BookDeleteMenuItem);
//		MenuB.add(BookMGRMenu);
//		// 借书管理菜单
//		BorrowBookMenu = new JMenu("借书管理");
//		BorrowBookMenuItem = new JMenuItem("书籍出借");
//		BorrowInfoMenuItem = new JMenuItem("出借信息修改");
//		BorrowBookMenu.add(BorrowBookMenuItem);
//		BorrowBookMenu.add(BorrowInfoMenuItem);
//		MenuB.add(BorrowBookMenu);
//		// --还书管理菜单
//		ReturnBookMenu = new JMenu("还书管理");
//		ReturnBookMenuItem = new JMenuItem("书籍还入");
//		ReturnInfoMenuItem = new JMenuItem("书籍还入信息修改");
//		ReturnBookMenu.add(ReturnBookMenuItem);
//		ReturnBookMenu.add(ReturnInfoMenuItem);
//		MenuB.add(ReturnBookMenu);
//		// --信息一览菜单--
//		InfoBrowseMenu = new JMenu("信息一览");
//		BookListMenuItem = new JMenuItem("书籍列表");
//		// BorrowBookListMenuItem=new JMenuItem("借阅情况表");
//		UserListMenuItem = new JMenuItem("用户列表");
//		InfoBrowseMenu.add(BookListMenuItem);
//		// InfoBrowseMenu.add(BorrowBookListMenuItem);
//		InfoBrowseMenu.add(UserListMenuItem);
//		// BorrowBookListMenuItem.addActionListener(this);
//		MenuB.add(InfoBrowseMenu);
//		// 借书卡管理
//		BookkaMenu = new JMenu("借书卡管理");
//		BookenvirMenuItem = new JMenuItem("借阅情况");
//		BookkaMenu.add(BookenvirMenuItem);
//		MenuB.add(BookkaMenu);
//
//		setJMenuBar(MenuB);

//		titleLabel = new JLabel(new ImageIcon(".\\dl.jpg"));
		
		c = getContentPane();
		c.setLayout(new BorderLayout());
		panel1 = new JPanel();
		panel1.setLayout(new BorderLayout());
//		panel1.add(titleLabel, BorderLayout.CENTER);
//		panel1.add(button, BorderLayout.CENTER);
		c.add(slider, BorderLayout.CENTER);
		setBounds(100, 50, 600, 450);

//		show();
//		// 设置初始功能
//		UserMGRMenu.setEnabled(false);
//		BookMGRMenu.setEnabled(false);
//		BorrowBookMenu.setEnabled(false);
//		ReturnBookMenu.setEnabled(false);
//		InfoBrowseMenu.setEnabled(false);
//		BookkaMenu.setEnabled(false);
	}

}
